package com.tianqu.tms.core.base;

import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;
import org.apache.log4j.helpers.Loader;
import org.apache.log4j.xml.DOMConfigurator;

/**
 * Log out
 * 
 */
public class LogManager {
	/** Fully Qualified Class Name */
	private static final String FQCN = LogManager.class.getName();

	/** Log4j Logger */
	private static Logger logger = null;

	private static LogManager myInstance = null;

	private LogManager() {
		logger = Logger.getLogger(FQCN);
	}

	/**
	 * 
	 * @param resourceName
	 */
	public synchronized static void init(String resourceName) {
		myInstance = new LogManager();

		if (resourceName.endsWith(".xml")) {
			logger.trace("xml格式log4j配置文件加载");
			DOMConfigurator.configure(Loader.getResource(resourceName));
		} else {
			logger.trace("properties格式log4j配置文件加载");
			PropertyConfigurator.configure(Loader.getResource(resourceName));
		}
	}

	/**
	 * 
	 * @return
	 */
	public static LogManager getInstance() {
		if (myInstance == null) {
			myInstance = new LogManager();
		}
		return myInstance;
	}

}